/*
 * Commands.h
 *
 *  Created on: 2 mars 2012
 *      Author: Jeff
 */

#ifndef COMMANDS_H_
#define COMMANDS_H_

#include "ArgumentHandler.hpp"
#include "config.h"

struct CommandEnv {
	void * arguments[SHELL_ARGCOUNT_MAX];
};

struct Command {
	void (*process)(struct CommandEnv *);
	const prog_uchar * name;
	int argCount;
	int argTypes[SHELL_ARGCOUNT_MAX];
};

struct CommandReference {
	void (*process)(struct CommandEnv *);
	const prog_uchar * name;
	const prog_uint8_t argCount;
	const prog_uint8_t argTypes[SHELL_ARGCOUNT_MAX];
};

class CommandHandler {
public:
	const struct CommandReference ** commands;
	ArgumentHandler * argumentHdl;
	int commandCount;
	CommandHandler();
	void registerArguments(ArgumentHandler * hdl);
	void registerAll(const struct CommandReference ** cmds, int cmdC);
	int matchCommand(char * query);
	void executeCommand(int cmd, struct CommandEnv * env);
	boolean parseCommandEnvironment(int cmd, char ** argStrings, struct CommandEnv * env);
};

#endif /* COMMANDS_H_ */
